package com.qf.mxapp.controller;

import com.qf.mxapp.pojo.User;
import com.qf.mxapp.pojo.dto.UserDto;
import com.qf.mxapp.result.ApiStatus;
import com.qf.mxapp.result.ResponseData;
import com.qf.mxapp.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("users")
public class UserController {
    @Resource
    private UserService userService;

    @GetMapping("code/{tel}")
    public ResponseData sendCode(@PathVariable String tel) throws Exception {
        Boolean isTrue = userService.sendCode(tel);
       if(isTrue){
           return new ResponseData(ApiStatus.SUCCESS);
       }else {
           return new ResponseData(ApiStatus.INTERNAL_SERVER_ERROR);
       }
    }

    @PostMapping("login")
    public ResponseData login(@RequestBody UserDto userDto) {
        User user = (User) userService.login(userDto);
        if(user == null){
            return new ResponseData(ApiStatus.CODE_ERROR);
        }else{
            return new ResponseData(ApiStatus.SUCCESS,user);
        }
    }
}
